<template>
  <rx-layout>
    <div slot="left" width="200" showButton="true">
      <rx-fit>
        <rx-category-treeeditor
          cat-key="BPM"
          read-key="task.read"
          :edit="false"
          @handSelect="handSelect"
          :async="true"
        ></rx-category-treeeditor>
      </rx-fit>
    </div>
    <div slot="center">
      <rx-fit  :isheader="isheader">
        <div slot="toolheader" foldheader="true" foldbtn="false" border="false">
          <span class="search-btn-box" v-if="!isheader">
            <span class="search-btn" @click.stop="searchshow"><i class="iconfont iconguolv"></i>
                {{$ti18('rxList.leachBtn','过滤')}}
            </span>
          </span>
        </div>
        <div btnalign="right"  slot="searchbar" v-if="fitSearch" @search="search" @cancel="cancel" @close="closeSearchbar">
          <a-form :layout="colLayout">
            <a-row :gutter="24">
              <a-col :span="colSpan">
                <a-form-item :label="i18n('form.itemTitle','事项标题')">
                  <a-input :placeholder="i18n('form.itemTitle','事项标题','input')"  v-model="queryParam['Q_i.SUBJECT__S_LK']" />
                </a-form-item>
              </a-col>
              <a-col :span="colSpan">
                <a-form-item :label="i18n('form.process','流程名称')">
                  <a-input :placeholder="i18n('form.process','流程名称','input')" v-model="queryParam['Q_d.NAME__S_LK']" />
                </a-form-item>
              </a-col>
              <a-col :span="colSpan" v-if="isheader">
                    <span class="table-page-search-submitButtons">
                      <a-button type="primary"  icon="search" @click="search">
                          {{$ti18('rxList.searchBtn','查询')}}
                      </a-button>
                      <a-button style="margin-left: 4px"  @click="cancel">{{$ti18('rxList.resetBtn','重置')}}</a-button>
                      <a @click="toggleAdvanced" style="margin-left: 8px">
                        {{ advanced ? i18n('list.putAwayBtn','收起') : i18n('list.expansionBtn','展开') }}
                        <a-icon :type="advanced ? 'up' : 'down'" />
                      </a>
                    </span>
              </a-col>

              <template v-if="advanced">
              <a-col :span="colSpan">
            <a-form-item :label="i18n('form.processKey','流程Key')">
              <a-input :placeholder="i18n('form.processKey','流程Key','input')" v-model="queryParam.Q_KEY__S_LK" />
            </a-form-item>
              </a-col>
              <a-col :span="colSpan">
                <a-form-item :label="i18n('form.processState','流程状态')">
                  <a-select :placeholder="i18n('form.processState','流程状态','input')" v-model="queryParam.Q_STATUS__S_LK">
                    <a-select-option :value="op['key']" v-for="op in opinionMap">{{ op.text }}</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :span="colSpan">
            <a-form-item :label="i18n('form.timeFrom','创建时间 从')">
              <a-date-picker
                style="width: 100%"
                :placeholder="i18n('form.timeFrom','创建时间 从','input')"
                v-model="queryParam.Q_CREATE_TIME__D_GE"
                format="YYYY-MM-DD"
              />
            </a-form-item>
              </a-col>
              <a-col :span="colSpan">
            <a-form-item :label="i18n('form.to','至')">
              <a-date-picker
                style="width: 100%"
                :placeholder="i18n('form.createTime','请输入任务创建时间')"
                v-model="queryParam.Q_CREATE_TIME__D_LE"
                format="YYYY-MM-DD"
              />
            </a-form-item>
              </a-col>
              </template>
            </a-row>
          </a-form>
        </div>
        <rx-grid
          ref="table"
          :bordered="isBorder"
          :allowRowSelect="true"
          :multiSelect="true"
          :columns="columns"
          :defaultPageSize="10"
          url="/api-bpm/bpm/core/bpmInst/getMyApprovedInsts"
          :queryParam="queryParam"
          data-field="result.data"
          :pageSizeOptions="['10', '30', '40']"
          id-field="hisId"
          :loadDataOnstart="true"
          @selectChange="onSelectChange"
        >
          <span slot="subject" slot-scope="{ text, record,index }">
           <a @click="instDetail(record)">{{text}}</a>
          </span>
          <span slot="status" slot-scope="{ text, status }">
            <a-tag :color="statusMap[text].color">
              <span>{{ statusMap[text].text }}</span>
            </a-tag>
          </span>
          <span slot="endTime" slot-scope="{ text, record, index }">
            {{ text }}
          </span>
          <span slot="action" slot-scope="{ text, record }" class="actionIcons">
            <!--            <span><a @click="retrieveTask(record)">取回</a></span>-->
            <span><a @click="instDetail(record)">{{$ti18('rxList.detailBtn','明细')}}</a></span>
            <span><a @click="transferTo(record)">{{i18n('form.forward','转发')}}</a></span>
          </span>
        </rx-grid>
      </rx-fit>
    </div>
  </rx-layout>
</template>


<script>
import { AppBaseList, RxLayout, Util, RxFit, RxGrid } from '@lowcode/jpaas-common-lib';
import BpmInstTransfer from "../core/BpmInstTransfer";
import RxCategoryTreeeditor from '@/components/redxun/rx-category-treeeditor'
import FlowUtil from "../js/FlowUtil";
export default {
  name: 'my-approved-tasks',
  mixins: [AppBaseList,FlowUtil],
  components: {
    RxLayout,
    RxFit,
    RxGrid,
    RxCategoryTreeeditor,
    BpmInstTransfer
  },
  data() {
    return {
      treeData: [],
      selTreeId: '',
      gridData: [],
      // 表头
      columns: [
        {
          title: this.$ti18('rxList.index','序号'),
          type: 'indexColumn',
          dataIndex: 'serial',
          scopedSlots: { customRender: 'serial' },
          width: 80,
        },
        {
          title: this.i18n('form.itemTitle','事项标题'),
          dataIndex: 'subject',
          width: 220,
          ellipsis: false,
          scopedSlots: { customRender: 'subject' },
        },
        {
          title: this.i18n('form.billNo','单号'),
          dataIndex: 'billNo',
          width: 120,
          ellipsis: false,
        },
        {
          title: this.i18n('form.edition','版本'),
          dataIndex: 'version',
          width: 80
        },
        {
          title: this.i18n('form.status','状态'),
          dataIndex: 'status',
          width: 100,
          scopedSlots: { customRender: 'status' },
        },
        {
          title: this.i18n('form.createTime2','创建时间'),
          dataIndex: 'createTime',
          width: 100
        },
        {
          title: this.i18n('form.completionTime','完成时间'),
          dataIndex: 'endTime',
          width: 100
        },
        {
          title: this.$ti18('rxList.action','操作'),
          dataIndex: 'action',
          width: 100,
          scopedSlots: { customRender: 'action' },
        },
      ],
      statusMap: {
        DRAFTED: { color: 'gray', text: this.i18n('statusMap.draft','草稿') },
        RUNNING: { color: 'red', text: this.i18n('statusMap.inOperation','运行中') }, //运行
        SUPSPEND: { color: 'black', text: this.i18n('statusMap.suspend','暂停') }, //运行
        CANCEL: { color: 'red', text: this.i18n('statusMap.cancel','作废') }, //作废
        SUCCESS_END: { color: 'green', text: this.i18n('statusMap.success','成功')  }, // 成功结束
        ERROR_END: { color: 'red', text:this.i18n('statusMap.end','异常结束') }, //异常结束
      }
    }
  },
  methods: {
      i18n(name, text, key) {
          return this.$ti18(name, text, "myApproved", key);
      },
    handSelect(curRow) {
      let selTreeId = curRow.treeId
      this.loadData({['Q_i.TREE_ID__S_EQ']:curRow.treeId});
    },
    instDetail(record) {
      this.openDetail(record.appId,record.instId);
    },
    transferTo(record){
        var instId=record.instId;
        Util.open({
            component: BpmInstTransfer,
            curVm: this,
            widthHeight: ['800px', '500px'],
            title: this.i18n('list.instance','转发流程实例') + record.subject  ,
            data: {
                instId: record.instId,
                send:true
            },
        }, function (action) {

        })
    },
    search() {
      this.$refs.table.loadData()
    },
    cancel() {
      this.resetSearch()
    },
    closeSearchbar(){
      //关闭过滤弹窗；（点击X触发）
      this.fitSearch = false ;
    },
    retrieveTask(record) {
        // let self_=this;
        // Util.open({
        //     component:BpmRetrieveTask,
        //     widthHeight:['800px','400px'],
        //     curVm:this,
        //     title: record.subject + '取回任务',
        //     data:{
        //         taskId:record.taskId,
        //         subject:record.subject
        //     }
        // },function (action){
        //     //这里没回调
        //     if(action=='ok'){
        //         self_.refreshGrid();
        //     }
        // });
    }
  }
}
</script>
<style scoped>

</style>

